package com.example.service.serviceImple;

import com.example.dao.UserDao;
import com.example.dao.VideoDao;
import com.example.entity.Video;
import com.example.entity.vo.VideoListVo;
import com.example.entity.vo.VideoSuggestVo;
import com.example.entity.vo.VideoVo;
import com.example.service.VideoService;
import com.example.util.BeanFactroy;

import java.util.List;

public class VideoServiceImpl implements VideoService {

    VideoDao videoDao = BeanFactroy.createBean(VideoDao.class);
    UserDao userDao = BeanFactroy.createBean(UserDao.class);

    //添加视频
    @Override
    public boolean addVideo(Video video) {
        return videoDao.addVideo(video);
    }

    //根据id查找视频
    @Override
    public Video queryVideoById(String id) {
        return videoDao.queryVideoById(id);
    }

    //查询所有视频
    @Override
    public List<Video> queryAllVideo() {
        return videoDao.queryAllVideo();
    }

    //按标题模糊查询视频
    @Override
    public List<Video> queryVideoByTitle(String criteria) {
        return videoDao.queryVideoByTitle(criteria);
    }

    //按id删除视频
    @Override
    public boolean deleteVideoById(String id) {
        return videoDao.deleteVideoById(id);
    }

    @Override
    public VideoVo queryVideoInfo(String id) {

        Video video = videoDao.queryVideoById(id);

        VideoVo videoVo = new VideoVo();

        videoVo.setId(video.getId());
        videoVo.setTitle(video.getTitle());
        videoVo.setUrl(video.getUrl());
        videoVo.setPlayNum(video.getPlayNum());
        videoVo.setLikes(video.getLikes());

        videoVo.setUser(userDao.queryUserById(video.getUserId()));

        return videoVo;
    }

    //查询视频页面视频信息和作者信息列表
    @Override
    public List<VideoSuggestVo> queryVideoInfoList(String id) {
        return videoDao.queryVideoInfoList(id);
    }

    //主页查询视频信息列表
    @Override
    public List<VideoListVo> queryVideoListInfo() {
        return videoDao.queryVideoListInfo();
    }

    @Override
    public List<Video> queryVideoByUserId(Long userId) {
        return videoDao.queryVideoByUserId(userId);
    }

}
